// ignore_for_file: constant_identifier_names

import 'package:pigeon/pigeon.dart';

@ConfigurePigeon(
  PigeonOptions(
    dartOut: 'lib/src/peripheral.g.dart',
    dartOptions: DartOptions(),
    kotlinOut:
        'android/src/main/kotlin/com/harth/flutter_ns_ble/Peripheral.g.kt',
    kotlinOptions: KotlinOptions(package: "com.harth.flutter_ns_ble"),
    swiftOut: 'ios/Classes/Peripheral.g.swift',
    swiftOptions: SwiftOptions(),

    dartPackageName: 'pigeon_example_package',
  ),
)

@EventChannelApi()
abstract class NSEventChannelApi {
  PeripheralEvent providePeripheralEvent();
  LogEvent provideLogEvent();
}

@HostApi()
abstract class PeripheralMethod {
  @async
  bool ensureInitialized(String address);
  @async
  bool connect(String address);

  @async
  bool disconnect(String address);

  @async
  bool write(String address, CMD cmd, Uint8List? value);

  @async
  bool startDFU(String address, String filePath);

  @async
  bool cancelDFU(String address);

  /// 返回文件存储地址
  @async
  String? startB1SyncData(String address, String? filePath, bool? deleteBeforeWrite);

  @async
  bool cancelB1SyncData(String address);
}


enum PeripheralState { disconnected, connecting, connected, disconnecting, ready }

class LogEvent{
  final int priority;
  final String message;

  LogEvent({required this.priority, required this.message});
}

sealed class PeripheralEvent{}

class PeripheralStateEvent extends PeripheralEvent {
  final String address;
  final PeripheralState state;
  PeripheralStateEvent(this.address, this.state);
}

class PeripheralNotifyEvent extends PeripheralEvent {
  final String address;
  final CMD cmd;
  final Uint8List? data;
  final Uint8List raw;
  PeripheralNotifyEvent({required this.address, required this.cmd, this.data, required this.raw});
}


class DFUStateEvent extends PeripheralEvent {
  final String address;
  final DFUState state;
  final int? sentSize;
  final int? totalSize;
  final int? stateCode;
  final String? errorMsg;
  DFUStateEvent({required this.address, required this.state, this.sentSize, this.totalSize, this.stateCode, this.errorMsg});
}

enum DFUState{
  idle,
  start,
  progress,
  completed,
  canceled,
}

class B1SyncDataEvent extends PeripheralEvent {
  final String address;
  final B1SyncDataState state;
  final int? receivedSize;
  final int? totalSize;
  final int? stateCode;
  final String? errorMsg;
  B1SyncDataEvent({required this.address, required this.state, this.receivedSize, this.totalSize, this.stateCode, this.errorMsg});
}

enum B1SyncDataState{
  idle,
  start,
  progress,
  completed,
  canceled,
}

enum CMD {
  magicCode,
  info,
  imei,
  imsi,
  measTag,
  measFlash,
  measStatus,
  measCount,
  measSN,
  measFlashCount,
  measIndex,
  rGSTSet,
  rGSTGet,
  ecgCtl,
  ecgData,
  ecgStatus,
  dfuInit,
  dfuPacket,
  dfuCheck,
  dfuEnd,
  unknow,
  writeFactSn,
  ios,
  android,
  stopSync,
  timeCache;
}

